#!/bin/bash

export IMAGE_NAME="my-redis-cluster:latest"

cd redis

docker build -t $IMAGE_NAME .

cd ..

mkdir 6371
mkdir 6372
mkdir 6373
mkdir 6374
mkdir 6375
mkdir 6376

cp redis/redis.conf 6371
sed -i 's/${PORT}/6371/g' 6371/redis.conf
sed -i 's/${PUB_IP}/8.140.165.13/g' 6371/redis.conf
sed -i 's/${PUB_PORT}/16371/g' 6371/redis.conf

cp redis/redis.conf 6372
sed -i 's/${PORT}/6372/g' 6372/redis.conf
sed -i 's/${PUB_IP}/8.140.165.13/g' 6372/redis.conf
sed -i 's/${PUB_PORT}/16372/g' 6372/redis.conf

cp redis/redis.conf 6373
sed -i 's/${PORT}/6373/g' 6373/redis.conf
sed -i 's/${PUB_IP}/8.140.165.13/g' 6373/redis.conf
sed -i 's/${PUB_PORT}/16373/g' 6373/redis.conf

cp redis/redis.conf 6374
sed -i 's/${PORT}/6374/g' 6374/redis.conf
sed -i 's/${PUB_IP}/8.140.165.13/g' 6374/redis.conf
sed -i 's/${PUB_PORT}/16374/g' 6374/redis.conf

cp redis/redis.conf 6375
sed -i 's/${PORT}/6375/g' 6375/redis.conf
sed -i 's/${PUB_IP}/8.140.165.13/g' 6375/redis.conf
sed -i 's/${PUB_PORT}/16375/g' 6375/redis.conf

cp redis/redis.conf 6376
sed -i 's/${PORT}/6376/g' 6376/redis.conf
sed -i 's/${PUB_IP}/8.140.165.13/g' 6376/redis.conf
sed -i 's/${PUB_PORT}/16376/g' 6376/redis.conf

docker run -d  --name redis-6371 \
 -p 6371:6371 \
 -p 16371:16371 \
 -v $PWD/6371/data/:/data/ \
 -v $PWD/6371/redis.conf:/usr/local/etc/redis/redis.conf \
 $IMAGE_NAME

docker run -d  --name redis-6372 \
 -p 6372:6372 \
 -p 16372:16372 \
 -v $PWD/6372/data/:/data/ \
 -v $PWD/6372/redis.conf:/usr/local/etc/redis/redis.conf \
 $IMAGE_NAME

docker run -d  --name redis-6373 \
 -p 6373:6373 \
 -p 16373:16373 \
 -v $PWD/6373/data/:/data/ \
 -v $PWD/6373/redis.conf:/usr/local/etc/redis/redis.conf \
 $IMAGE_NAME

docker run -d  --name redis-6374 \
 -p 6374:6374 \
 -p 16374:16374 \
 -v $PWD/6374/data/:/data/ \
 -v $PWD/6374/redis.conf:/usr/local/etc/redis/redis.conf \
 $IMAGE_NAME

docker run -d  --name redis-6375 \
 -p 6375:6375 \
 -p 16375:16375 \
 -v $PWD/6375/data/:/data/ \
 -v $PWD/6375/redis.conf:/usr/local/etc/redis/redis.conf \
 $IMAGE_NAME

docker run -d  --name redis-6376 \
 -p 6376:6376 \
 -p 16376:16376 \
 -v $PWD/6376/data/:/data/ \
 -v $PWD/6376/redis.conf:/usr/local/etc/redis/redis.conf \
 $IMAGE_NAME

docker exec -it redis-6371 redis-cli --cluster create 172.30.124.30:6371  172.30.124.30:6372  172.30.124.30:6373  172.30.124.30:6374  172.30.124.30:6375  172.30.124.30:6376  --cluster-replicas 1 -a 9191991

#docker-compose up -d
